// (c) Copyright 2013-2014 Stephen Gold <sgold@sonic.net>
// Distributed under the terms of the GNU General Public License

/*
 This file is part of the Bats Game.

 The Bats Game is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by the
 Free Software Foundation, either version 3 of the License, or (at your
 option) any later version.

 The Bats Game is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.

 You should have received a copy of the GNU General Public License
 along with the Bats Game.  If not, see <http://www.gnu.org/licenses/>.
 */
package bats.ui;

import com.jme3.input.KeyInput;
import java.util.logging.Logger;
import jme3utilities.ui.Hotkey;
import jme3utilities.ui.InputMode;

/**
 * The input mode for the bind screen.
 *
 * @author Stephen Gold <sgold@sonic.net>
 */
public class BindInputMode
        extends InputMode {
    // *************************************************************************
    // constants

    /**
     * message logger for this class
     */
    final private static Logger logger =
            Logger.getLogger(BindInputMode.class.getName());
    // *************************************************************************
    // fields
    /**
     * corresponding screen: set by constructor
     */
    final private BindScreen screen;
    // *************************************************************************
    // constructors

    /**
     * Instantiate a disabled mode. After instantiation, the first method
     * invoked should be initialize().
     *
     * @param screen corresponding screen (not null)
     */
    BindInputMode(BindScreen screen) {
        super("bind");

        assert screen != null;
        this.screen = screen;
    }
    // *************************************************************************
    // ActionListener methods

    /**
     * Process an action from the GUI or keyboard.
     *
     * @param actionString textual description of the action (not null)
     * @param ongoing true if the action is ongoing, otherwise false
     * @param ignored
     */
    @Override
    public void onAction(String actionString, boolean ongoing, float ignored) {
        screen.onAction(actionString, ongoing, ignored);
    }
    // *************************************************************************
    // InputMode methods

    /**
     * Add the hotkey bindings.
     */
    @Override
    protected void defaultBindings() {
        bind("close", KeyInput.KEY_ESCAPE);

        for (Hotkey hotkey : Hotkey.getAll()) {
            if (BindScreen.isExempt(hotkey)) {
                continue;
            }
            int keyCode = hotkey.keyCode();
            String actionString = String.format("select %d", keyCode);
            bind(actionString, keyCode);
        }
    }
}